package com.lishe.lishe.lishe.module.excitation.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.lishe.lishe.R;
import com.lishe.lishe.lishe.base.BaseActivity;
import com.lishe.lishe.lishe.common.Globals;

/**
 * Created by shino on 2017/10/25.
 * 可视范围
 */

public class VisualRangeActivity extends BaseActivity implements View.OnClickListener {

    private Button callBack;
    private Button confirm;
    private TextView title;
    private ImageView selectCompanyImage;
    private ImageView selectTaImage;
    private ImageView selectMeImage;
    private RelativeLayout companyLayout;
    private RelativeLayout taLayout;
    private RelativeLayout meLayout;
    private int selectType = 1;//全公司范围
    private int TYPE_COMPANY = 1;//全公司范围
    private int TYPE_ME = 2;//仅我所在部门
    private int TYPE_TA = 3;//仅Ta所在部门

    public static void jump(Activity activity, int requscode) {
        Intent intent = new Intent(activity, VisualRangeActivity.class);
        activity.startActivityForResult(intent, requscode);
    }

    public static void jump(Fragment fragment, int requscode) {
        Intent intent = new Intent(fragment.getActivity(), VisualRangeActivity.class);
        fragment.startActivityForResult(intent, requscode);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_visual_range);
        initView();
    }

    private void initView() {
        callBack = findViewById(R.id.title_left_button);
        title = findViewById(R.id.title_text_title);
        confirm = findViewById(R.id.confirm);
        selectCompanyImage = findViewById(R.id.select_company_image);
        selectTaImage = findViewById(R.id.select_ta_image);
        selectMeImage = findViewById(R.id.select_me_image);
        companyLayout = findViewById(R.id.company_layout);
        taLayout = findViewById(R.id.ta_layout);
        meLayout = findViewById(R.id.me_layout);
        title.setText("可视范围");
        selectType = TYPE_COMPANY;
        changeSeletSattus(selectType);
        setListener();
    }

    private void setListener() {
        callBack.setOnClickListener(this);
        confirm.setOnClickListener(this);
        companyLayout.setOnClickListener(this);
        taLayout.setOnClickListener(this);
        meLayout.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.title_left_button:
                finish();
                break;
            case R.id.company_layout:
                selectType = TYPE_COMPANY;
                changeSeletSattus(selectType);
                break;
            case R.id.ta_layout:
                selectType = TYPE_TA;
                changeSeletSattus(selectType);
                break;
            case R.id.me_layout:
                selectType = TYPE_ME;
                changeSeletSattus(selectType);
                break;
            case R.id.confirm:
                Intent intent = new Intent();
                intent.putExtra("type", selectType);
                setResult(RESULT_OK, intent);
                finish();
                break;
        }
    }

    private void changeSeletSattus(int type) {
        if (type == TYPE_COMPANY) {
            selectCompanyImage.setImageResource(R.mipmap.sel_choice_icon);
            selectTaImage.setImageResource(R.mipmap.circle_gray);
            selectMeImage.setImageResource(R.mipmap.circle_gray);
        } else if (type == TYPE_TA) {
            selectTaImage.setImageResource(R.mipmap.sel_choice_icon);
            selectCompanyImage.setImageResource(R.mipmap.circle_gray);
            selectMeImage.setImageResource(R.mipmap.circle_gray);
        } else if (type == TYPE_ME) {
            selectMeImage.setImageResource(R.mipmap.sel_choice_icon);
            selectCompanyImage.setImageResource(R.mipmap.circle_gray);
            selectTaImage.setImageResource(R.mipmap.circle_gray);
        }
    }
}
